package com.cyl.job;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.cyl.manager.vip.service.IVipAutoRenewService;

/**
 * VIP自动续费定时任务
 *
 * @author system
 * @date 2024-01-01
 */
@Component
public class VipAutoRenewJob {

    private static final Logger log = LoggerFactory.getLogger(VipAutoRenewJob.class);

    @Autowired
    private IVipAutoRenewService vipAutoRenewService;

    /**
     * 处理VIP自动续费任务
     * 每小时执行一次
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void processAutoRenewTasks() {
        log.info("开始执行VIP自动续费定时任务");

        try {
            int processedCount = vipAutoRenewService.processAutoRenewTasks();
            log.info("VIP自动续费定时任务执行完成，处理了 {} 条记录", processedCount);
        } catch (Exception e) {
            log.error("VIP自动续费定时任务执行异常", e);
        }
    }



    /**
     * 清理过期的自动续费记录
     * 每天凌晨2点执行
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void cleanExpiredAutoRenewRecords() {
        log.info("开始清理过期的VIP自动续费记录");

        try {
            // TODO: 实现清理逻辑，删除超过最大重试次数且失败的记录
            log.info("过期VIP自动续费记录清理完成");
        } catch (Exception e) {
            log.error("清理过期VIP自动续费记录异常", e);
        }
    }
}
